package com.smart.cloud.gateway.config;

import com.smart.cloud.gateway.fliter.IPKeyResolver;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 代码方式配置路由
 *
 * <bean id="user" class=""></>
 */
//@Configuration
@Service("apiGatewayConfig")
public class ApiGatewayConfig {
    @Bean
    public KeyResolver keyResolver() {
        return new IPKeyResolver();
    }
    /**
     * 第一步 定义路由
     * 第二步  定义断言
     * 第一步 定义过滤器
     * http://127.0.0.1:9000/api/user
     */
//    @Bean
//    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
//        return builder.routes()
//                .route("default-router",
//                        predicates -> predicates
//                                .path("/api/**")
//                                .filters(filter -> filter.stripPrefix(1))
//                                .uri("http://localhost:8091"))
//                .build();
//    }
}
